from flask_login import login_required

from ..base import base
from flask import request
from ..service.CustomerMessagesService import *
from exts import success, page_success


@base.route('/api/customer/messages/add', methods=['POST'])
@login_required
def customer_messages_add_api():
    '''
    添加客户信息
    :return:
    '''
    customer_message = request.get_json()
    customer_messages_add(customer_message)
    return success(customer_message)


@base.route('/api/customer/messages/update', methods=['POST'])
@login_required
def customer_messages_update_api():
    '''
    添加客户信息
    :return:
    '''
    customer_message = request.get_json()
    customer_messages_update(customer_message)
    return success(customer_message)


@base.route('/api/customer/messages/delete', methods=['POST'])
@login_required
def customer_messages_delete_api():
    '''
    删除客户信息
    :return:
    '''
    customer_message = request.get_json()
    customer_messages_delete(customer_message['id'])
    return success(customer_message['id'])


@base.route('/api/customer/messages/detail', methods=['POST'])
@login_required
def customer_messages_detail_api():
    '''
    查询客户信息
    :return:
    '''
    customer_message = request.get_json()
    return success(customer_messages_get_by_id(customer_message['id']))


@base.route('/api/customer/messages/page', methods=['POST'])
@login_required
def customer_messages_page_api():
    '''
    分页查询
    :return:
    '''
    customer_message = request.get_json()
    page = customer_messages_page(customer_message['pageNum'], customer_message['pageSize'])
    return page_success(page.total, page.items)


# ===================================pc web端api接口====================================================
@base.route('/api/customer/messages/create', methods=['POST'])
def customer_messages_create_api():
    '''
    添加客户信息 pc web端
    :return:
    '''
    customer_message = request.get_json()
    customer_messages_add(customer_message)
    return success(customer_message)
